<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Content-Language" content="zh-CN">
	<meta name="author" content="管雷鸣">
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
</head>
<body>

<script src="https://res.zvo.cn/websocket.js/websocket.js"></script>
<script>
websocket.connect({
	url:'ws://localhost:8081/', //服务端的WebSocket地址
	onopen:function(){ //如果不需要，此不传即可。
		websocket.send({"type":"CONNECT","token":"123456"}); //当WebSocket通道连接成功后，自动给服务器发送一条json格式的消息
	},
	onmessage:function(message){ //如果不需要，此不传即可
		console.log(message); //服务端发送来的消息会在这里接收到
		document.getElementById('showMessage').innerHTML = JSON.stringify(message) + '<br/>' + document.getElementById('showMessage').innerHTML;
	}
});
</script>

<div id="showMessage" style="width:500px; height:300px; font-size: 12px;">服务器发送来的消息在此显示</div>
<button onclick="websocket.send({type:'MSG', text:'Hello Word'}); ">发送个Hello Word</button>

</body>
</html>